<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0.1
 *	LISENSE: FL87MPRYOA0R - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Auto Classifieds
 *	DOMAIN: www.siyaradiali.com
 *	FILE: RLHOOK.CLASS.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

class rlHook extends reefless
{
	/**
	* @var validator class object
	**/
	var $rlValid;
	
	/**
	* @var common class object
	**/
	var $rlCommon;
	
	/**
	* @var hooks array
	**/
	var $rlHooks;
	
	/**
	* class constructor
	**/
	function rlHook()
	{
		global $rlValid, $rlCommon;
		
		$this -> rlValid = $rlValid;
		$this -> rlCommon = $rlCommon;
		
		/* get hooks */
		$this -> getHooks();
	}

	/**
	* get all active hooks
	*
	* @return array - hooks array
	**/
	function getHooks()
	{
		$this -> setTable('hooks');
		$tmp_hooks = $this -> fetch( array('Name', 'Code'), array('Status' => 'active') );
		$this -> resetTable();
		
		foreach ($tmp_hooks as $key => $value)
		{
			if (!$hooks[$tmp_hooks[$key]['Name']])
			{
				$hooks[$tmp_hooks[$key]['Name']] = $tmp_hooks[$key]['Code'];
			}
			else
			{
				$tmp_hook = $hooks[$tmp_hooks[$key]['Name']];
				
				unset($hooks[$tmp_hooks[$key]['Name']]);
				
				if (is_array($tmp_hook))
				{
					$tmp_hook[] = $tmp_hooks[$key]['Code'];
					$hooks[$tmp_hooks[$key]['Name']] = $tmp_hook;
				}
				else
				{
					$hooks[$tmp_hooks[$key]['Name']][] = $tmp_hooks[$key]['Code'];
					$hooks[$tmp_hooks[$key]['Name']][] = $tmp_hook;
				}
			}
			unset($tmp_hook);
		}

		unset($tmp_hooks);
		$this -> rlHooks = $hooks;
		$GLOBALS['hooks'] = $hooks;
	}
	
	/**
	* load hook
	*
	* @param string - hook name
	*
	**/
	function load( $name = false )
	{
		if ( is_array($name) )
		{
			$name = $name['name'];
			$hooks = $GLOBALS['hooks'];
		}
		else
		{
			$hooks = $this -> rlHooks;
		}

		$code = isset($hooks[$name]) ? $hooks[$name] : '';
		if ( !empty($code) )
		{
			if (is_array($code))
			{
				foreach ($code as $item)
				{
					eval($item);
				}
			}
			else
			{
				eval($code);
			}
		}
	}
}